package Like1;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
//@WebFilter(urlPatterns = "/Like/*")
public class CoreFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request=(HttpServletRequest) req;
        String uri = request.getRequestURI();
        if("/Like/login.jsp".equals(uri) || uri.endsWith(".css")){
            chain.doFilter(req,resp);
            return;
        }
        HttpServletResponse response=(HttpServletResponse) resp;
        HttpSession session = request.getSession();
        Object uid = session.getAttribute("UID");
        if(uid==null){
            response.sendRedirect("/Like/login.jsp");

        }
    }

    @Override
    public void destroy() {

    }
}
